
local danglian = fk.CreateSkill{
  name = "xiaobai__danglian",
}

Fk:loadTranslationTable{  
  ["xiaobai__danglian"] = "党连",
  [":xiaobai__danglian"] = "每回合各限一次，你不因使用或打出失去牌后，你可以横置并摸两张牌；你受到非属性伤害时，你可以重置并防止此伤害。",
  ["#danglian__draw"] = "党连：你可以横置并摸两张牌",
  ["#danglian__prevent"] = "党连：你可以重置并防止此伤害",

  ["$xiaobai__danglian1"] = "司马公尸居余气，形神已离，不足虑矣。",
  ["$xiaobai__danglian2"] = "兵可立威，此役伐蜀，大将军当建奇功。"
}

danglian:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(self) or player:getMark("danglian1-turn") > 0 or player.chained then return end
    if player:hasSkill(self)then
      for _, move in ipairs(data) do
        if move.from == player and move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResponse then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{
      skill_name = danglian.name,
      prompt = "#danglian__draw"
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "danglian1-turn", 1)
    player:setChainState(true)
    if player.dead then return end
    player:drawCards(2, danglian.name)
  end
})

danglian:addEffect(fk.DamageInflicted, {
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(self) or player:getMark("danglian2-turn")>0 or not player.chained or target ~= player then return end
    if data.damageType == fk.NormalDamage then
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{ 
      skill_name = danglian.name,
      prompt = "#danglian__prevent"})
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "danglian2-turn", 1)
    player:setChainState(false)
    if player.dead then return end
    data:preventDamage()
  end
})


return danglian